package cn.itcast.bos.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.domain.base.Area;
import cn.itcast.bos.domain.page.PageBean;
import cn.itcast.bos.domain.take_delivery.Promotion;
import cn.itcast.bos.repository.AreaRepository;
import cn.itcast.bos.repository.PromotionRepository;
import cn.itcast.bos.service.AreaService;
import cn.itcast.bos.service.PromotionService;
import cn.itcast.crm.domain.Customer;
@Service 
@Transactional
public class PromotionServiceImpl implements PromotionService {
	@Autowired
	public PromotionRepository  promotionRepository ;

	@Override
	public void save(Promotion model) {
		promotionRepository.save(model);
		
	}

	@Override
	public Page<Promotion> findPageData(PageRequest pageable) {
		return promotionRepository.findAll(pageable);
	}
	/**
	 * 前台页面显示,bos_management作为服务端
	 * 
	 */
	@Override
	public PageBean<Promotion> findPageData(int page, int rows) {
		Pageable pageable = new PageRequest(page-1, rows);
		Page<Promotion> pageData = promotionRepository.findAll(pageable);
		//创建pageBean对象
		PageBean<Promotion> pageBean = new PageBean<Promotion>();
		pageBean.setContent(pageData.getContent());
		pageBean.setTotalElements(pageData.getTotalElements());
		return pageBean;
				
		
	}

	//使用id查询
	
	@Override
	public Promotion findById(Integer id) {
		return promotionRepository.findOne(id);
	}

	//更新状态
	@Override
	public void updateStatus(Date date) {
			promotionRepository.updataStatus(date);
	}

	




}
